<?php

namespace app\index\controller;
use app\index\model\BaseModel;
use think\Controller;
use think\Request;

class Index extends Controller
{
    public function index()
    {
        //获取首页需要的数据
        //处理图片
        $lunboimg = BaseModel::selectAll('lunboimg');
        foreach ($lunboimg as &$k){
            $k["lunbo_name"] = '/school/public/'.$k["lunbo_name"];
        }
        $paomadengimg =  BaseModel::selectAll('paomadengimg');
        foreach ($paomadengimg as &$k){
            $k["paomadeng_name"] = '/school/public/'.$k["paomadeng_name"];
        }
        $this->view->assign([
            "menu" => BaseModel::selectAll('menu'),
            "lunboImg" => $lunboimg,
            "paomadengImg" => $paomadengimg,
            "project1" => BaseModel::select('article','project_id',1),
            "project2" => BaseModel::select('article','project_id',2),
            "project3" => BaseModel::select('article','project_id',3),
            "project4" => BaseModel::select('article','project_id',4),
            "project5" => BaseModel::select('article','project_id',5)
        ]);//把数据传到页面
        return $this->fetch('index');
    }
    public function detail(){
        $request = Request::instance();
        $param = $request->param();
        //从里面的二级标签里进入
        if(array_key_exists("tagId",$param) == true){
            $tagId = $param['tagId'];
            $menuId = $param['menuId'];
            $this->view->assign([
                "menu" => BaseModel::selectAll('menu'),
                "rowsTag" => BaseModel::select('tag','menu_id',$menuId),
                "rowsArticle" => BaseModel::select('article','tag_id',$tagId),
            ]);//把数据传到页面
            return $this->fetch('detail');
        }else{
            //从导航列表进入
            $menuId = $param['menuId'];
            $this->view->assign([
                "menu" => BaseModel::selectAll('menu'),
                "rowsTag" => BaseModel::select('tag','menu_id',$menuId),
                "rowsArticle" => BaseModel::select('article','menu_id',$menuId),
            ]);//把数据传到页面
            return $this->fetch('detail');
        }
    }
    public function detail_article(){
        $request = Request::instance();
        $param = $request->param();
        $articleId = $param["articleId"];
        $this->view->assign([
            "menu" => BaseModel::selectAll('menu'),
            "rows" => BaseModel::select("article",'id',$articleId),
            "rowsLeft" => BaseModel::select("article",'id',$articleId-1),
            "rowsRight" => BaseModel::select("article",'id',$articleId+1),
        ]);//把数据传到页面
        return $this->fetch('detail-article');
    }
}
